const Router = require('koa-router');
const router = new Router();
const attendanceController = require('../controllers/attendance.controller');
const authMiddleware = require('../middlewares/auth.middleware');

// 考勤相关API路由

// 获取所有考勤记录
router.get('/', authMiddleware.authenticateToken, attendanceController.getAllAttendances);

// 获取单个考勤记录
router.get('/:id', authMiddleware.authenticateToken, attendanceController.getAttendanceById);

// 创建新考勤记录
router.post('/', authMiddleware.authenticateToken, authMiddleware.authorize(['admin', 'teacher']), attendanceController.createAttendance);

// 批量创建考勤记录
router.post('/batch', authMiddleware.authenticateToken, authMiddleware.authorize(['admin', 'teacher']), attendanceController.batchCreateAttendances);

// 更新考勤记录
router.put('/:id', authMiddleware.authenticateToken, authMiddleware.authorize(['admin', 'teacher']), attendanceController.updateAttendance);

// 删除考勤记录
router.delete('/:id', authMiddleware.authenticateToken, authMiddleware.authorize(['admin']), attendanceController.deleteAttendance);

// 获取学生的考勤记录
router.get('/student/:studentId', authMiddleware.authenticateToken, attendanceController.getStudentAttendances);

// 获取班级的考勤记录
router.get('/class/:classId', authMiddleware.authenticateToken, authMiddleware.authorize(['admin', 'teacher']), attendanceController.getClassAttendances);

// 获取指定日期的考勤记录
router.get('/date/:date', authMiddleware.authenticateToken, authMiddleware.authorize(['admin', 'teacher']), attendanceController.getAttendancesByDate);

// 获取考勤统计信息
router.get('/stats/class/:classId', authMiddleware.authenticateToken, authMiddleware.authorize(['admin', 'teacher']), attendanceController.getClassAttendanceStats);

module.exports = router;